import BaseEntity from "../entity/BaseEntity";
import Sql from "./Sql";
import SqlStatement from "./SqlStatement";

export default class ProxyHandler<T extends BaseEntity>{
    async apply(target: Function, thisArg, args){
        const sql = Sql[target.name](args[0]);
        const statement = new SqlStatement(sql);
        if(target.name === 'page'){
            const countSql = Sql.countByPage(args[0]);
            statement.setCountSql(countSql)
        }
        const result = await target.apply(thisArg, [statement])
        return result
    }
}
